<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/3/17
  Time: 13:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="header.jsp"%>
</head>
<body>
    <form id="formId" class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="name" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-block">
                <input type="text" name="age" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div  class="layui-form-item">
            <label class="layui-form-label">请选择班级</label>
            <div class="layui-input-inline">
                <select name="banjiId">
                    <option value="">请选择省</option>
                    <option value="1">java1807</option>
                    <option value="2">java1812</option>
                    <option value="3">java230301</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn"  onclick="submitForm()" lay-filter="demo1">添加</button>
            </div>
        </div>
    </form>

    <script>
        var form;
        layui.use(['form'],function() {
            form = layui.form;
        });

        function submitForm() {
            $.post(
                '<%=request.getContextPath()%>/user?method=add',
                $('#formId').serialize(),
                function(jsonResult) {
                    console.log(jsonResult);
                    if (jsonResult.ok) {
                        mylayer.okMsg(jsonResult.msg)
                        //关闭弹出框
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //刷新父页面
                        window.parent.location.reload();
                    } else {
                        mylayer.errorMsg(jsonResult.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
